/****************************************************************************/
/*																			*/
/*	 FILE:	  xmsg.h														*/
/*	 DATE:	  13/06/97														*/
/*	 PURPOSE: Messages Definitions											*/
/*	 TAB STOPS : 4															*/
/*	 HISTORY:																*/
/*	 Version	Date			Written	by		 Notes						*/
/*	 1.0		13/06/1997		SCM				 Initial implementation		*/
/*	 2.0		31/07/1997		SCM				 Acces to PHYSICAL Task		*/
/*								instead	of PHYSICAL	Driver					*/
/*	 1.06		01/02/1999		SCM				 Add phmsg_header_t	structure	*/
/*									 phmsg_header_t.type : char	---> short	*/
/*																			*/
/*--------------------------------------------------------------------------*/
/*	 GENERAL COMMENTS														*/
/*																			*/
/****************************************************************************/
#ifndef	__XMSG_H
#define	__XMSG_H

/*--------------------------------------------------------------------------*/
/* Symbol Definitions														*/
/*--------------------------------------------------------------------------*/
#ifdef _MSC_VER
//#define	MAXSLOTID	2		/* Max count of	DVB	modules							*/
#define	MAXSLOTID	1	     	/* zet  only used in test */
#else
#define	MAXSLOTID	1
#endif
#define	MAXTCID		8		/* Max count of	transport connections					*/
#define	MAXSSNB	   32		/* Max count of	sessions								*/

#ifndef	NULL
#define	NULL		(void *)0
#endif

#define	PHYSICAL	1		/* Physical	Task								*/
#define	LINK		2		/* Link	Task									*/
#define	TRANS		3		/* Transport Task								*/
#define	SESS		4		/* Session Task									*/
#define	RM			5		/* RM Task										*/
#define	ITC_DT		6
#define	ITC_TIMER	7		//add by pmy
#define	AID_EXTINT	8		//add by hhl
#define SPY_TASK_AID	9		//spy task
#define LSC_RCV 10
#define LSC_SND 11
#define SAS_TASK_AID	12
#define HC_TASK_AID	13
#define PHYREAD_TASKAID	20

#define	GETTASKNAME(task) ((task)==PHYSICAL?"PHYS_TASK":((task)==LINK?"LINK_TASK":((task)==TRANS?"TRAN_TASK":((task)==SESS?"SESS_TASK":	((task)==ITC_TIMER?"TIMER_TASK":((task)==ITC_DT?"DT_TASK":((task)==RM?"RM_TASK":((task)==SPY_TASK_AID?"SPY_TASK":"UNKN_TASK"))))))))

/*--------------------------------------------------------------------------*/
/* Messages	Definitions														*/
/*--------------------------------------------------------------------------*/

// Messages	tags
// Physical	Layer
#define	PH_INSERT		0x01
#define	PH_DATA			0x02
#define	PH_ERROR		0x03
#define	PH_EXTRACT		0x04
// end of physical layer

// add by pmy
#define XMG_EXIT		0x08
#define DT_TMPOLL		0x09

// Timeout Messages	Base
#define	TMID_TRPT_PEND_BASE	0x50	// Transport layer timer base
#define	TMID_TRPT_POLL_BASE	0x60	// Transport polling timer base
// Example: TIMEOUT/TIMEPOLL for tcid 3	= TIMEOUT/TIMEPOLL + tcid =	0x53/0x63

#define	TMID_SESS_PEND_BASE	0x70	// Session layer timer base

#define	TMID_DT_POLL_BASE	0x28 	// date_time timer base
#define	MAX_DT_TIMER		   8 	// date_time timer count

#define TMID_APP_PEND_BASE	0x30	// APP timer base
#define APP_TIMER_COUNT		   8	// APP timer count

#define TMID_APP_ENTERMENU  	TMID_APP_PEND_BASE
#define TMID_APP_CLOSEMMI	    TMID_APP_PEND_BASE+1
#define TMID_APP_CLOSEAPPMMI	TMID_APP_PEND_BASE+2

// Link	Layer
#define	LN_CONNECT		0x11
#define	LN_DISCONNECT	0x12
#define	LPDU			0x13
#define	LN_ERROR		0x14
#define	LN_ACK			0x15

// status from LN_ERROR
#define	LN_OK			1	// Success
#define	LN_PHYSICAL		2	// hardware	layer error
// end of link layer

//add by pmy, for app
#define APP_OPEN_SS_REQ		0x17
#define APP_OPEN_SS_RSP		0x18
#define APP_CLOSE_SS_REQ	0x19
#define APP_CLOSE_SS_RSP	0x1A
#define APP_SS_OPENED		0x1C
#define APP_SS_BROKEN		0x1D
#define APP_APDU			0x1E
#define APP_TC_BROKEN		0x1F

// Transport Layer
#define	TP_CONNECT		0x21
#define	TP_DISCONNECT	0x22
#define	TPDU			0x23
#define TP_TMPEND		0x24		//pend timer
#define TP_TMPOLL		0x25		//poll timer
// end of transport	layer

// Session Layer
#define	SS_TC_CREATED	0x31
#define	SS_DELETE_TC	0x32
#define	SS_TC_DELETED	0x33
#define	SPDU			0x34
#define	RCVSPDU			0x35 //add by pmy
#define SS_TMPEND		0x36
// end of session layer

// Resource	Manager	layer
#define	RM_TC_CREATED	0x41
#define	RM_OPEN_SS_REQ	0x42
#define	RM_OPEN_SS_RSP	0x43
#define	RM_SS_OPENED	0x44
#define	APDU			0x45
#define	RM_CLOSE_SS		0x46
#define	RM_SS_CLOSED	0x47
#define	RM_DELETE_TC	0x48
#define	RM_TC_DELETED	0x49

#define APP_TMPEND		0x4A		//pend timer

// DVB-CI Messages
#include "citag.h"

char* getxmsgname(unsigned int xmsgType);
#define	XMSG_NAME getxmsgname

// Messages	structures
// Physical	Layer
typedef	struct	// PH_INSERT
{
	unsigned short m_slotId;	// physical	reference for DVB module
	unsigned char  m_status;	// result of module's connection
	unsigned short m_negoSize;	// negociated physical buffer size
}ph_insert_t;

typedef	struct 	// PH_ERROR
{
	unsigned short m_slotId;		// physical	reference for DVB module
	unsigned char  m_status;		// error's type
}ph_error_t;

typedef	struct	// PH_DATA
{
	unsigned short	m_slotId;	// physical	reference for DVB module
	unsigned short	m_len;			// length of the LPDU buffer following the structure
	unsigned char*	m_pbData;		// physical	buffer beginning
}ph_data_t;

typedef	struct // PH_EXTRACT
{
	unsigned short m_slotId;	// physical	reference for DVB module
}ph_extract_t;

// Link	Layer
typedef	struct  // LN_CONNECT
{
	unsigned short m_slotId;	// physical	reference for DVB module
	unsigned char  m_status;	// result of module's connection
	unsigned short m_negoSize;	// negociated physical buffer size
}link_connect_t;

typedef	struct	// LPDU
{
	unsigned short m_slotId;	// physical	reference for DVB module
	unsigned short m_len;			// length of the LPDU buffer
	unsigned char* m_pbLpdu;		// pointer of a	LPDU buffer
}link_lpdu_t;


typedef	struct	// LN_ERROR
{
	unsigned short m_slotId;	// physical	reference for DVB module
	unsigned char  m_status;		// error's type
}link_error_t;


typedef	struct // LN_ACK
{
	unsigned short m_slotId;		// physical	reference for DVB module
}link_act_t;

typedef	struct  // LN_DISCONNECT
{
	unsigned short m_slotId;		// physical	reference for DVB module
}link_disconn_t;
// end of Link layer

// Transport Layer
typedef	struct  // TP_CONNECT
{
	unsigned short m_slotId;		// physical	reference for DVB module
}tran_conn_t;

typedef	struct  // TP_DISCONNECT
{
	unsigned short m_slotId;		// physical	reference for DVB module
}tran_disconn_t;

typedef	struct // TPDU
{
	unsigned short 	m_slotId;		// physical	reference for DVB module
	unsigned char 	m_tcid;			// transport connection	identifier
	unsigned char*	m_pbTpdu;		// pointer of a	TPDU buffer
	unsigned long 	m_len;			// length of the TPDU buffer
}tran_tpdu_t;
// end of Transport	layer

// Session Layer
typedef	struct // SS_TC_CREATED
{
	unsigned char m_tcid;			// transport connection	identifier
}sess_tc_created_t;

typedef	struct // SPDU
{
	unsigned char 	m_tcid;			// transport connection	identifier
	unsigned char*	m_pbSpdu;		// pointer of a	SPDU buffer
	unsigned long 	m_len;			// length of the SPDU buffer
}tran_spdu_t;

typedef	struct  // SS_DELETE_TC
{
	unsigned char m_tcid;			// transport connection	identifier
}tran_ssdeletetc_t;

typedef	struct  // SS_TC_DELETED
{
	unsigned char m_tcid;			// transport connection	identifier
}ss_tc_deleted_t;
// end of Session layer

// Session Layer
typedef	struct  // RM_TC_CREATED
{
	unsigned char m_tcid;			// transport connection	identifier
}rm_tc_created_t;

typedef	struct  // RM_DELETE_TC
{
	unsigned char m_tcid;			// transport connection	identifier
}rm_delete_tc_t;

typedef	struct  // RM_TC_DELETED
{
	unsigned char m_tcid;			// transport connection	identifier
}rm_tc_deleted_t;

typedef	struct  // RM_OPEN_SS_REQ
{
	unsigned char 	m_tcid;		// transport connection	identifier
	unsigned short 	m_ssnb;		// session number
	unsigned long 	m_ressId;	// resource	identifier
}rm_open_ss_req_t;

typedef	struct  // RM_OPEN_SS_RSP
{
	unsigned short 	m_ssnb;		// session number
	unsigned char 	m_status;	// status of the response
	unsigned char 	m_rtcid;	// tcid	routing
	unsigned long	m_ressId;	// resource identifier returned
}rm_open_ss_rsp_t;

typedef	struct   // RM_SS_OPENED
{
	unsigned short m_ssnb;		// session number
	unsigned char  m_tcid;		// tcid
	unsigned char  m_status;	// status of the response,only for module
	unsigned long  m_ressId;	// resource	identifier,only for module
}rm_ss_opened_t;

typedef	struct  // RM_CLOSE_SS
{
	unsigned short m_ssnb;		// session number
}rm_close_ss_t;

typedef	struct  // RM_SS_CLOSED
{
	unsigned short m_ssnb;		// session number
	unsigned char m_status;		// status of the closing
}rm_ss_closed_t;

typedef	struct	// APDU
{
	unsigned short 	m_ssnb;			// session number
	unsigned char*	m_pbApdu;		// pointer of a	rPDU buffer
	unsigned long 	m_len;			// length of the RPDU buffer
}rm_apdu_t;
// end of Resource Manager layer


// App Layer ,add by pmy
typedef	struct  // APP_OPEN_SS_REQ
{
	unsigned char 	m_tcid;					// transport connection	identifier
	unsigned short 	m_ssnb;					// session number,only for host
	unsigned long 	m_ressId;				// resource	identifier
}app_open_ss_req_t;

typedef	struct  // APP_OPEN_SS_RSP
{
	unsigned short 	m_ssnb;		// session number
	unsigned char 	m_status;	// status of the response
	unsigned char 	m_tcid;		// tcid
	unsigned char 	m_rtcid;	// routing tcid
	unsigned long 	m_ressId;	// resource	identifier
}app_open_ss_rsp_t;

typedef	struct  // APP_CLOSE_SS_REQ
{
	unsigned short 	m_ssnb;		// session number
}app_close_ss_req_t;

typedef	struct  // APP_SS_OPENED
{
	unsigned short 	m_ssnb;		// session number
	unsigned char 	m_tcid;		// tcid
}app_ss_opened_t;

typedef	struct  // APP_SS_BROKEN
{
	unsigned short 	m_ssnb;		// session number
}app_ss_broken_t;

typedef	struct  // APP_TC_BROKEN
{
	unsigned char 	m_tcid;		// tcid
}app_tc_broken_t;

typedef	struct  // APP_APDU
{
	unsigned char   m_tcid;		// tcid
	unsigned short 	m_ssnb;		// session number
	unsigned long	m_apduLen;	//apdu total len ( tag+lenField+body [+tag+lenField+body+..])
	unsigned char*	m_pbApdu;	//apdu [+ apdu +...]
}app_apdu_t;
// end of App layer

typedef struct
{
	unsigned short	m_timerId;
	unsigned long	m_param;
}ci_timer_t;

// DVB Messages
typedef	union
{
	ph_error_t			m_ph_error;
	ph_insert_t			m_ph_insert;	// Physical	Layer
	ph_data_t			m_ph_data;
	ph_extract_t		m_ph_extract;
	link_connect_t		m_ln_connect;	// Link	Layer
	link_error_t		m_ln_error;
	link_lpdu_t			m_lpdu;
	link_disconn_t		m_ln_disconn;
	link_act_t			m_ln_ack;
	tran_conn_t			m_tran_conn;			// Transport Layer
	tran_disconn_t		m_tran_disconn;
	tran_tpdu_t			m_tpdu;
	sess_tc_created_t	m_ss_tccreated;
	tran_spdu_t			m_spdu;
	tran_ssdeletetc_t	m_tran_ssdeletetc;
	ss_tc_deleted_t		m_ss_tc_deleted;
	rm_tc_created_t		m_rm_tc_created;			// Session Layer
	rm_open_ss_req_t	m_rm_open_ss_req;
	rm_open_ss_rsp_t	m_rm_open_ss_rsp;
	rm_ss_opened_t		m_rm_ss_opened;
	rm_apdu_t			m_apdu;
	rm_close_ss_t		m_rm_close_ss;
	rm_ss_closed_t		m_rm_ss_closed;
	rm_delete_tc_t		m_rm_delete_tc;
	rm_tc_deleted_t		m_rm_tc_deleted;
	app_open_ss_req_t	m_app_open_ss_req;			//App Layer,add by pmy
	app_open_ss_rsp_t	m_app_open_ss_rsp;
	app_close_ss_req_t	m_app_close_ss_req;
	app_ss_opened_t		m_app_ss_opened;
	app_apdu_t			m_app_apdu;
	app_ss_broken_t		m_app_ss_broken;
	app_tc_broken_t		m_app_tc_broken;
	ci_timer_t			m_timer;
}msg_body_t;


// Kind	of received	informations according to received evenements
typedef	struct
{
	unsigned char	m_type;		// DVB Message's Type
	unsigned char	m_sndrcver;	// Message's Sender	(4 left	bits) /	Receiver (4	right bits)
	msg_body_t		m_bd;
}xmsg_t;


#endif	// !__XMSG_H
